package mo.golden;

import java.util.Stack;

public class L03_05 {

    private Stack<Integer> stack = new Stack<>();
    private Stack<Integer> tmp = new Stack<>();

    public void push(int val) {
        if (stack.isEmpty()) {
            stack.push(val);
        } else {
            while (!stack.isEmpty() && stack.peek() < val) {
                tmp.push(stack.pop());
            }
            stack.push(val);
            while (!tmp.isEmpty()) {
                stack.push(tmp.pop());
            }
        }
    }

    public void pop() {
        if (!stack.isEmpty()) {
            stack.pop();
        }

    }

    public int peek() {
        if (stack.isEmpty()) {
            return -1;
        }
        return stack.peek();
    }

    public boolean isEmpty() {
        return stack.isEmpty();
    }

}
